package com.study.leetcode;

import java.util.Arrays;

public class Solution_414 {
    public int thirdMax(int[] nums) {
        int[] array = Arrays.stream(nums).distinct().sorted().toArray();
        if (array.length >= 3) {
            return array[array.length - 3];
        }
        return array[array.length - 1];
    }

    public static void main(String[] args) {
        int[] arr = {4, 5, 6, 9, 8, 7, 1, 10};
        Solution_414 solution414 = new Solution_414();
        int thirdMax = solution414.thirdMax(arr);
        System.out.println("thirdMax = " + thirdMax);
    }
}
